<template>
  <div class="dashboard-editor-container">
    <el-card>
      <el-form :model="form" size="mini" label-position="top" ref="form">
        <el-row :gutter="10">
          <el-col :lg="5" :md="6">
            <el-form-item label="案例编号" prop="CASENO">
              <el-input size="small" placeholder="请输入案例编号" v-model="form.CASENO"></el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="5" :md="6">
            <el-form-item label="生成方式" prop="CREATETYPE">
              <el-select v-model="form.CREATETYPE" filterable clearable placeholder="请选择生成方式">
                <el-option v-for="(item,index) in creatTypeOption" :key="index" :label="item.code+'—'+item.val"
                  :value="item.code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="5" :md="6">
            <el-form-item label="案例类型" prop="CASETYPE">
              <el-select v-model="form.CASETYPE" filterable clearable placeholder="请选择案例类型">
                <el-option v-for="(item,index) in caseTypeOption" :key="index" :label="item.code+'—'+item.val"
                  :value="item.code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="5" :md="6">
            <el-form-item label="文件类型" prop="FILETYPE">
              <el-select v-model="form.FILETYPE" filterable clearable placeholder="请选择文件类型">
                <el-option v-for="(item,index) in fileTypeOption" :key="index" :label="item.code+'—'+item.val"
                  :value="item.code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :lg="4" :md="6">
            <el-form-item label="案例状态" prop="CASESTATUS">
              <el-select v-model="form.CASESTATUS" filterable clearable placeholder="请选择案例状态">
                <el-option v-for="(item,index) in caseStatusOption" :key="index" :label="item.code+'—'+item.val"
                  :value="item.code"></el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
        </el-row>
        <el-row :gutter="10">
          <el-col :lg="6" :md="10" class="searchBtnMarginTop">
            <el-button type="primary" icon="el-icon-search" :loading="loading" size="mini"
              @click="queryCaseData('form')">查询</el-button>
            <el-button type="warning" size="mini" icon="el-icon-refresh" @click="clearForm('form')">重置</el-button>
            <!-- <el-button type="success" size="mini" icon="el-icon-plus" @click="addData('')">新增导入案例</el-button> -->
          </el-col>
        </el-row>
      </el-form>
      <el-table :data="tableData" border highlight-current-row class="tableMarginTop">
        <el-table-column prop="CASENO" align="center" label="案例编号"></el-table-column>
        <el-table-column prop="CASENAME" align="center" label="案例名称"></el-table-column>
        <el-table-column prop="CASETYPE" align="center" label="案例类型" :formatter="dataFormat"></el-table-column>
        <el-table-column prop="CREATETYPE" align="center" label="生成方式" :formatter="dataFormat"></el-table-column>
        <el-table-column prop="TASKID" align="center" label="任务ID"></el-table-column>
        <el-table-column prop="FILETYPE" align="center" label="文件类型" :formatter="dataFormat"></el-table-column>
        <el-table-column prop="FILEFORMAT" align="center" label="文件格式"></el-table-column>
        <el-table-column prop="FILEPATH" align="center" label="文件路径" width="100"></el-table-column>
        <el-table-column prop="FILENAME" align="center" label="文件名"></el-table-column>
        <el-table-column prop="CREATEDATE" align="center" label="创建日期"></el-table-column>
        <el-table-column prop="CREATETIME" align="center" label="创建时间"></el-table-column>
        <el-table-column prop="CREATER" align="center" label="创建人"></el-table-column>
        <el-table-column prop="CASESTATUS" align="center" label="案例状态" :formatter="dataFormat"></el-table-column>
        <el-table-column prop="DELDESC" align="center" label="删除原因"></el-table-column>
        <el-table-column label="操作" align="center"  fixed="right">
          <template slot-scope="scope">
            <div>
              <!-- <el-button type="success" size="mini" @click="add(scope.row)" v-if="scope.row.CASESTATUS === '0'">新增学习任务
              </el-button> -->
              <el-button type="danger" size="mini" @click="review(scope.row)" >审核
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <el-row>
        <el-col>
          <el-pagination style="text-align: right; margin-top:20px;" :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize" @size-change="handleInSizeChange" @current-change="handleInCurrentChange"
            :current-page="currpage" background layout="total,sizes, prev, pager, next, jumper" :total="tableTotal">
          </el-pagination>
        </el-col>
      </el-row>
    </el-card>
    <!-- <component :is="dialogList.addDialog" :option="addOptions" @refreshTable="queryCaseData"></component> -->
    <!-- <component :is="dialogList.addTaskDialog" :option="addTaskOptions" @refreshTable="queryCaseData"></component> -->
    <!-- <component :is="dialogList.reviewDialog" :option="reviewOptions" @refreshTable="queryCaseData"></component> -->
  </div>
</template>
<script>
  import getGlobalParams from "@/common/utils/getGlobalParams";
  import request from "@/common/utils/requestQC";
  import toolBox from "@/common/utils/toolBox";
  // import addDialog from "./dialog/addDialog";
  // import addTaskDialog from "./dialog/addTaskDialog";
  // import reviewDialog from "./dialog/reviewDialog";
  import queyData from "@/message/QCManage/caseManage/caseDataQuery";
  import requestWFM from "@/common/utils/requestWFM";
  export default {
    data() {
      return {
        creatTypeOption: [{
          'code': "0",
          'val': "手动导入"
        }, {
          'code': "1",
          'val': "质检关联"
        }],
        caseStatusOption: [{
          'code': "0",
          'val': "通过"
        }, {
          'code': "1",
          'val': "申请"
        }, {
          'code': "2",
          'val': "不通过"
        }],
        fileTypeOption: [{
          'code': "video",
          'val': "视频"
        }, {
          'code': "voice",
          'val': "语音"
        }, {
          'code': "chat",
          'val': "文字"
        }],
        caseTypeOption: [{
          'code': "0",
          'val': "成功案例"
        }, {
          'code': "1",
          'val': "失败案例"
        }],
        operaflagOption: [{
          'code': "0",
          'val': "已通过"
        }, {
          'code': "2",
          'val': "删除"
        }],
        fileFormatOption: [{
          'code': "1",
          'val': "AVI"
        }, {
          'code': "2",
          'val': "mov"
        }, {
          'code': "3",
          'val': "rmvb"
        }, {
          'code': "4",
          'val': "rm"
        }, {
          'code': "5",
          'val': "FLV"
        }, {
          'code': "6",
          'val': "mp4"
        }, {
          'code': "7",
          'val': "3GP"
        }],
        // dialogList: {
        //   addDialog,
        //   addTaskDialog,
        //   reviewDialog
        // },
        // addOptions: {
        //   isShow: false,
        //   title: "",
        //   row: {}
        // },
        // addTaskOptions: {
        //   isShow: false,
        //   title: "",
        //   row: {}
        // },
        reviewOptions: {
          isShow: false,
          title: "",
          row: {}
        },
        tableTotal: 1,
        currpage: 1,
        pageSize: getGlobalParams.get("PageSize"),
        tableData: [],
        form: {
          CASENO: "",
          CREATETYPE: "",
          CASETYPE: "",
          FILETYPE: "",
          CASESTATUS: "1"
        },
        loading: false
      };
    },
    mounted() {
      this.queryCaseData();
    },
    methods: {
      async queryCaseData(row) {
        let resBody = new queyData();
        resBody.data.CASENO = this.form.CASENO;
        resBody.data.CREATETYPE = this.form.CREATETYPE;
        resBody.data.CASETYPE = this.form.CASETYPE;
        resBody.data.FILETYPE = this.form.FILETYPE;
        resBody.data.CASESTATUS = this.form.CASESTATUS;
        resBody.data.PageFlag = 4;
        resBody.data.CurrPage = this.currpage;
        resBody.data.PageRowNum = this.pageSize;
        let response = await request(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.tableData = response.BODY.RSPSTRUCT;
          this.tableTotal = response.BODY.TotalRowNum;
          this.currpage = response.BODY.NowPageNum;
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" +
              response.SYS_HEAD.ReturnCode +
              "，错误信息：" +
              response.SYS_HEAD.ReturnMessage
          });
        }
      },
      // 新增案例数据
      // async addData() {
      //   this.addOptions.creatTypeOption = this.creatTypeOption;
      //   this.addOptions.caseStatusOption = this.caseStatusOption;
      //   this.addOptions.fileTypeOption = this.fileTypeOption;
      //   this.addOptions.caseTypeOption = this.caseTypeOption;
      //   this.addOptions.fileFormatOption = this.fileFormatOption;
      //   this.addOptions.isShow = true
      //   this.addOptions.title = '新增案例数据'
      // },

      //新增案例学习任务
      // async add(row) {
      //   this.addTaskOptions.CASENO = row.CASENO;
      //   this.addTaskOptions.isShow = true;
      //   this.addTaskOptions.title = '新增案例学习任务'
      // },

      //审核
      async review(row) {
        this.$router.push({
                name: 'caseApprove',
                params: {
                  title: '案例审核',
                  row:row
                }
              });
      },

      dataFormat(row, column) {
        if (column.property == "CASETYPE") {
          return row[column.property] == '0' ? '成功案例' : row[column.property] == '1' ? '失败案例' : ''
        } else if (column.property == "CREATETYPE") {
          return row[column.property] == '0' ? '手动导入' : row[column.property] == '1' ? '质检关联' : ''
        } else if (column.property == "FILETYPE") {
          return row[column.property] == 'video' ? '视频' : row[column.property] == 'voice' ? '语音' : row[column
            .property] == 'chat' ? '文字' : ''
        } else if (column.property == "CASESTATUS") {
          return row[column.property] == '0' ? '通过' : row[column.property] == '1' ? '申请中' : row[column.property] ==
            '2' ? '不通过' : ''
        }
        //枚举设备形式
        // if (column.property == "CHANNELTYPE")
        //   return this.findName(this.channelOption, row[column.property]);
        // if (column.property == "BUSINESSTYPE")
        //   return this.findName(this.typeOption, row[column.property]);
        // if (column.property == "TRANSCODE")
        //   return this.findCode(this.relationOption, row[column.property]);
        // if (column.property == "SCORETEMPLATEID")
        //   return this.findTemplate(this.SCORETEMPLATEIDOption, row[column.property]);
      },
      findCode(arr, val) {
        let data = arr.filter(item => {
          return item.TRANSCODE == val;
        });
        if (data.length) return data[0].TRANSCODE + " - " + data[0].TRANSNAME;
      },
      findName(arr, val) {
        let data = arr.filter(item => {
          return item.FIELDKEY == val;
        });
        if (data.length) return data[0].FIELDKEY + " - " + data[0].FIELDVALUE;
      },
      findTemplate(arr, val) {
        let data = arr.filter(item => {
          return item.SCORETEMPLATEID == val;
        });
        if (data.length)
          return data[0].SCORETEMPLATEID + " - " + data[0].SCORETEMPLATENAME;
      },
      //前端分页
      handleInCurrentChange(val) {
        this.currpage = val;
        // console.log(`当前页: ${val}`);
        this.queryCaseData();
      },
      handleInSizeChange(val) {
        this.pageSize = val;
        this.queryCaseData();
      },
      // 重置查询条件
      clearForm(item) {
        // 重置表格
        this.$refs["" + item].resetFields();
      }
    }
  };

</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
